﻿@{
    ViewBag.Title = "RetrialDetails";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<link href="~/Content/styles/BillDetail.css?v=1.3" rel="stylesheet" />
<script src="~/Content/scripts/jquery/ajaxfileupload.js"></script>
<script>
    var Man = '@ViewBag.Man';
    var keyValue = request('keyValue');
    var State = "", State1 = "", State2 = "", State3 = "", Id = "", BillState = 1;
    var BillState = 1, ApprovalState = 0;
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    var hashTable = new Object();
    var Code = "";
    $(function () {
        InitialPage();
        InitControl();
        GetGrid1();
    });
    //初始化数据
    function InitControl() {
        if (!!keyValue) {
            $.SetForm({
                url: "../../QualificationManage/Retrial/GetBillInfo",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#Code").html(data.BillInfo.Code);

                    $("#CityBurceauCode").val(data.BillInfo.CityBurceauCode);

                    Id = data.BillInfo.Id;
                    $("#State").text(GetState(data.BillInfo.State));
                    $("#FileSubmitCount").text(data.BillInfo.FileSubmitCount);
                    $("#BillInfo").SetWebControls(data.BillInfo);
                    $("#SQRXX").SetWebControls(data.MemberInfo);
                    GetGrid1();
                    GetGrid2(data.CheckRecordList);
                    $("#State").text(GetS(data.CheckRecordList));
                    State = data.BillInfo.State;
                    if (State == 4) { //材料提交
                        $("#CLTJ").css({ "backgroundColor": "#FFCC99" });
                    }


                }
            })
        }
    }

    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $('.profile-content').height($(window).height() - 20);
        $('.profile-nav').height($(window).height() - 20);


    }
    //侧面切换显示/隐藏
    function profileSwitch(id) {
        if (id == "BillContent") {
            $("#TrialRecord").hide();
            $("#BillContent").show();
        }
        else {
            $("#BillContent").hide();
            $("#TrialRecord").show();
        }
    };


    //资料收集
    function GetGrid1() {
        
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable1');
        $gridTable.jqGrid({
            url: "../../QualificationManage/Retrial/GetMaterialList?keyValue=" + Id,
            postData: { "keyValue": keyValue },
            datatype: "json",
            height: 360,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Code", hidden: true },
                { label: "资料编号", name: "RuleCode", hidden: true },
                { label: "资料名称", name: "Name", index: "Name", width: 80, align: "left",sortable: false },
                {
                    label: "必须提交", name: "IsSubmit", index: "IsSubmit", width: 80, align: "left", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1)
                            return "<span style='color: #b91a1a;'>是</span>";
                        else
                            return "<span style='color: #cecece;'>否</span>";
                    }
                },
                 {
                     label: "必须上传", name: "IsUpload", index: "IsUpload", width: 80, align: "left", sortable: false,
                     formatter: function (cellvalue, options, rowObject) {
                         if (cellvalue == 1)
                             return "<span style='color: #b91a1a;'>是</span>";
                         else
                             return "<span style='color: #5cb85c;'>否</span>";
                     }
                 },
                  {
                      label: "是否提交", name: "CommitState", index: "CommitState", width: 80, align: "left", sortable: false,
                      formatter: function (cellvalue, options, rowObject) {
                          if (cellvalue == 1) return "<i class='fa fa-check-square-o ' style='margin-left:10px;'><i/>";
                          else return "<i class='fa fa-square-o' style='margin-left:10px;'><i/>";

                      }
                  },
                {
                    label: "是否上传", name: "UploadState", index: "UploadState", width: 80, align: "left", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 1)
                            return "<i class='fa fa-check ' style='margin-left:10px;'><i/>";
                        else {
                            if (BillState >1) return "";
                            else
                                return " <i class='fa fa-upload' style='margin-left:10px;'><input class=\"fileImage\" id=\"fileImage_" + options.rowId + "_" + options.pos + "\"type=\"file\"  name=\"fileselect[]\"  style=\"position: absolute; width: 80px; height: 28px;opacity: 0; margin-top: -20px;  margin-left: -10px;\" onchange=\"UploadFile(" + options.rowId + "," + options.pos + ")\" /> ";
                        }

                    }
                },
                { label: "文件名", name: "FileName", index: "FileName", width: 100, align: "left", sortable: false},
                { label: "资料路径", name: "FileUrl", hidden: true },
                { label: "提交人", name: "CreateUserName", index: "CreateUserName", width: 80, align: "left" ,sortable: false},
                { label: "提交人ID", name: "CreateUserId", hidden: true },
                { label: "提交时间", name: "CreateDate", index: "CreateDate", width: 80, align: "left", sortable: false },
                { label: "接收人", name: "ReceiveUserName", index: "ReceiveUserName", width: 80, align: "center", sortable: false },
                { label: "接收时间", name: "ReceiveDate", index: "ReceiveDate", width: 80, align: "left", sortable: false },
                {
                    label: "是否合格", name: "IsQualified", index: "IsQualified", width: 100, align: "left",sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 1: return "<i class='fa fa-check fa-2x' style='color:green;margin-left:10px;'><i/>"; break;
                            default: return ""; break;
                        }
                    }
                },
                { label: "说明", name: "Memo", index: "Memo", width: 80, align: "left",sortable: false }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            onCellSelect: function (rowid, iCol, cellcontent, e) {
                
                if (iCol == 6 && BillState == 1) {
                    //提交资料
                    var sss = $gridTable.getCell(rowid, 7);
                    if (e.target.className == 'fa fa-square-o' && sss.indexOf("UploadFile") < 0) {
                        $gridTable.setCell(rowid, iCol, "1");
                        $gridTable.setCell(rowid, 10, "@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserName");
                        $gridTable.setCell(rowid, 11, "@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserId");
                        $gridTable.setCell(rowid, 12, "@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")");
                    }
                    else {
                        $gridTable.setCell(rowid, iCol, "0");
                        $gridTable.setCell(rowid, 10, null);
                        $gridTable.setCell(rowid, 11, null);
                        $gridTable.setCell(rowid, 12, null);
                    }
                }
            }
        })

    }


    //  url: "../../QualificationManage/Retrial/UploadFile",
    function UploadFile(rowid, iCol) {
        var rowData = $("#gridTable1").jqGrid('getRowData', rowid);
        var files = document.getElementById('fileImage_' + rowid + '_' + iCol).files;
        if (files.length > 0 && rowData != null) {
            $.ajaxFileUpload({
                url: "../../QualificationManage/Retrial/UploadFile",
                secureuri: false,
                fileElementId: 'fileImage_' + rowid + '_' + iCol,
                data: { keyValue: rowData.RuleCode },
                success: function (data, status) {
                    
                    var resObj = JSON.parse(data.body.innerText);
                    var ss = resObj.resultdata.split(',');
                    hashTable[ss[0]] = ss[1];
                    $('#gridTable1').setCell(rowid, 8, files[0].name);
                    $('#gridTable1').setCell(rowid, 9, ss[1]);
                    $('#gridTable1').setCell(rowid, 7, 1);
                },
                error: function (data, status, e) {
                    alert(e);
                }
            });

        }
    }


    //审核记录
    function GetGrid2(data) {
        var selectedRowIndex = 0;
        $gridTable = $("#gridTable2");

        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
                  { label: "主键", name: "Id", hidden: true },
                  { label: "提交时间", name: "Date", index: "Date", width: 200, align: "center", sortable: false },
                  { label: "审核人", name: "CheckMan", index: "CheckMan", width: 200, align: "center", sortable: false },
                  { label: "审核时间", name: "CheckDate", index: "CheckDate", width: 200, align: "center", sortable: false },
                  {
                      label: "审核结果", name: "CheckFlag", index: "CheckFlag", width: 300, align: "center", sortable: false,
                      formatter: function (cellvalue, options, rowObject) {
                          var Msg = "<span  class='label' style='background-color:";
                          if (rowObject.Type == 1) {
                              if (cellvalue == 0) {
                                  Msg += "#B05B5C'>" + "初审未通过"
                              }
                              else {
                                  Msg += "#BCD186'>" + "初审通过"
                              }
                          }
                          if (rowObject.Type == 2) {
                              if (cellvalue == 0) {
                                  Msg += "#839B27'>" + "材料未通过"
                              }
                              else {
                                  Msg += "#81B981'>" + "材料通过"
                              }
                          }
                          if (rowObject.Type == 3) {
                              if (cellvalue == 0) {
                                  Msg += "#F09005'>" + "市局审批未通过"
                              }
                              else {
                                  Msg += "#5CB85C'>" + "市局审批通过"
                              }
                          }
                          if (rowObject.Type == 4) {
                              if (cellvalue == 0) {
                                  Msg += "#f00'>" + "复审未通过"
                              }
                              else {
                                  Msg += "#5CB85C'>" + "复审通过"

                              }
                          }
                          Msg += "</span>";
                          return Msg;
                      }
                  },
                  { label: "不通过原因", name: "CheckMemo", index: "CheckMemo", width: 650, align: "center", sortable: false },
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager2",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        $gridTable[0].addJSONData(data);

    }

    //初审信息
    function Detail() {
        var Code = keyValue;
        top.tablist.newTab({
            id: "TrialForm",
            title: '初审详情【' + Code + '】',
            closed: true,
            icon: "fa fa-eye",
            url: top.contentPath + '/QualificationManage/FirstTrial/Form?keyValue=' + keyValue
        });
    }

    //审批
    function Rdo_Trial(s, a) {
        switch (a) {
            case 1:
                State1 = s;
                if (s == 1) {
                    $("#Try1").attr("hidden", "hidden");
                    $("#Memo" + s).val("");
                    $(".SLBH").removeAttr("hidden");
                }
                else {
                    $("#Try1").removeAttr("hidden");
                    $(".SLBH").attr("hidden", "hidden");
                }
                if (State1 != 1) {
                    $("#SJ_Submit").attr("disabled", "disabled");
                    $("#SLZX_Submit").attr("disabled", "disabled");
                }
                break;
            case 2:
                State2 = s;
                if (s == 1) {
                    $("#Try2").attr("hidden", "hidden");
                    $("#Memo" + s).val("");
                }
                else {
                    $("#Try2").removeAttr("hidden");
                }
                if (State2 != 1) {
                    $("#SLZX_Submit").attr("disabled", "disabled");
                }
                break;
            case 3:
                State3 = s;
                if (s == 1) {
                    $("#Try3").attr("hidden", "hidden");
                    $("#Memo" + s).val("");
                }
                else {
                    $("#Try3").removeAttr("hidden");
                }
                break;
            default:

        }


    }



    //获取状态
    function GetState(value) {
        var Msg = "";
        switch (value) {
            case 1: Msg = "初审中（初次)";
                break;
            case 2: Msg = "初审中（再次）";
                break;
            case 3: Msg = "初审未通过";
                break;
            case 4: Msg = "递交资料中";
                break;
            case 5: Msg = "市局审批中（材料通过）";
                break;
            case 6: Msg = "复审（市局审批通过）";
                break;
            case 7: Msg = "复审通过";
                break;
            case 8: Msg = "复审未通过";
                break;
            case 9: Msg = "客户撤回";
                break;
            default: Msg = "---";
                break;
        }
        return Msg;
    }

    function GetS(data) {
        var s = [];
        for (var i = 0; i < data.length; i++) {
            s.push(Date.parse(data[i].Date.replace(/-/g, "/")));
        }
        
        max = Math.max.apply(null, s);
        for (var i = 0; i < data.length; i++) {
            if (s[i] == max) {
                var Msg = "";
                if (data[i].Type == 1) {
                    if (data[i].CheckFlag == 0) {
                        Msg = "初审未通过"
                    }
                    else {
                        Msg = "初审通过"
                    }
                }
                if (data[i].Type == 2) {
                    if (data[i].CheckFlag == 0) {
                        Msg = "材料未通过"
                        $("#Memo1").val(data[i].CheckMemo)
                        $("#Try1").removeAttr("hidden");
                        $("#CL_UChk").attr("checked", "checked");

                    }
                    else {
                        Msg = "材料通过"
                        $("#Submit").attr("disabled", "disabled");
                        $("#CL_Chk").attr("checked", "checked");
                        $("#SJ_Submit").removeAttr("disabled");
                        $("#SJSP").css({ "backgroundColor": "#FFCC99" });
                        $("#CLTJ").attr("disabled", "disabled");
                        $("#CityBurceauCode").attr("disabled", "disabled");
                    }
                }
                if (data[i].Type == 3) {
                    if (data[i].CheckFlag == 0) {
                        Msg = "市局审批未通过"
                        $("#Memo2").val(data[i].CheckMemo)
                        $("#Try2").removeAttr("hidden");
                        $("#SJ_UChk").attr("checked", "checked");
                    }
                    else {
                        Msg = "市局审批通过";
                        $("#SJ_Submit").attr("disabled", "disabled");
                        $("#Submit").attr("disabled", "disabled");
                        $("#SLZX_Submit").removeAttr("disabled");
                        $("#CL_Chk").attr("checked", "checked");
                        $("#SJ_Chk").attr("checked", "checked");
                        $(".CL_Rdo").attr("disabled", "disabled");
                        $(".SJ_Rdo").attr("disabled", "disabled");
                        $("#CityBurceauCode").attr("disabled", "disabled");
                        $("#SLZXSP").css({ "backgroundColor": "#FFCC99" });
                    }
                }
                if (data[i].Type == 4) {
                    if (data[i].CheckFlag == 0) {
                        Msg = "复审未通过"
                        $("#Memo3").val(data[i].CheckMemo);
                        $("#SJ_Submit").attr("disabled", "disabled");
                        $("#SLZX_Submit").attr("disabled", "disabled");
                        $("#Submit").attr("disabled", "disabled");
                        $("#CL_Chk").attr("checked", "checked");
                        $("#CityBurceauCode").attr("disabled", "disabled");
                        $("#SJ_Chk").attr("checked", "checked");
                        $("#SLZX_Uchk").attr("checked", "checked");
                        $(".CL_Rdo").attr("disabled", "disabled");
                        $(".SJ_Rdo").attr("disabled", "disabled");
                        $(".SHZX_Rdo").attr("disabled", "disabled");
                        $(".SLZX_Chk").attr("checked", "checked");
                        $("#Try3").removeAttr("hidden");
                        $("#SLZXSP").css({ "backgroundColor": "#FFCC99" });
                        $("#Memo3").attr("disabled", "disabled");
                        $("#Memo3").val(data.BillInfo.CheckMemo);
                    }
                    else {
                        Msg = "复审通过";
                        $("#SJ_Submit").attr("disabled", "disabled");
                        $("#SLZX_Submit").attr("disabled", "disabled");
                        $("#Submit").attr("disabled", "disabled");
                        $("#CityBurceauCode").attr("disabled", "disabled");
                        $("#CL_Chk").attr("checked", "checked");
                        $("#SJ_Chk").attr("checked", "checked");
                        $("#SLZX_Chk").attr("checked", "checked");
                        $(".CL_Rdo").attr("disabled", "disabled");
                        $(".SJ_Rdo").attr("disabled", "disabled");
                        $(".SHZX_Rdo").attr("disabled", "disabled");
                        $(".SLZX_Chk").attr("checked", "checked");
                        $("#SLZXSP").css({ "backgroundColor": "#FFCC99" });
                    }
                }
                return Msg;
            }
        }


    }
</script>
<style>
    .form-control {
        border: none;
    }
</style>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="profile-nav">
                <ul style="padding-top: 20px;">
                    <li class="active" onclick="profileSwitch('BillContent')">单据内容</li>
                    <li onclick="profileSwitch('TrialRecord')">审核记录</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="profile-content" style="background: #fff; ">
                <div id="BillContent">
                    <table class="form" id="BillInfo" style="margin-top: 20px;">
                        <tr>
                            <td class="formTitle">单据编号：</td>
                            <td class="formValue"><a href="#" onclick="Detail()" id="Code" style="color:blue; font-size:18px; text-decoration:underline;">XXXXX</a></td>
                            <td class="formTitle">创建时间：</td>
                            <td class="formValue"><input class="form-control" readonly id="CreateDate" type="text" /></td>
                            <td class="formTitle">初审通过时间：</td>
                            <td class="formValue"><input class="form-control" readonly id="FirstCheckDate" type="text" /></td>
                            <td class="formTitle">审批人：</td>
                            <td><input class="form-control" readonly id="FirstCheckMan" type="text" /></td>
                        </tr>
                        <tr>
                            <td class="formTitle">复审状态：</td>
                            <td class="formValue" colspan="4">
                                <span style="color: red; font-size: 24px; " id="State"></span>
                            </td>
                            <td></td>
                        </tr>
                        <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="8"></td> </tr>
                        <tr style="height:10px;"></tr>
                        <tr>
                            <td><h4>资料收集</h4></td>
                            <td></td>
                            <td>第<span style="color:red;font-size:24px;" id="FileSubmitCount"></span>次提交</td>
                            <td></td>
                            <td class="formTitle">资料提交日期：</td>
                            <td class="formValue"><input class="form-control" readonly id="Date" type="text" /></td>
                        </tr>
                    </table>
                    <br />

                    <div class="center-Panel">
                        <div class="gridPanel">
                            <table id="gridTable1"></table>
                        </div>
                    </div>
                    <div style="height:10px;width:1px;"></div>
                    <table class="form" id="CLTJ">
                        <tr style="height:10px;"></tr>
                        <tr>
                            <td></td>
                            <td style="text-align:right;">审核人：</td>
                            <td>@ViewBag.Man</td>
                            <td style="text-align:right;">审核时间：</td>
                            <td>@LeSoft.Util.Time.GetToday("yyyy-MM-dd HH:mm:ss")</td>
                            <td style="text-align:right;">审核结果：</td>
                            <td>
                                &nbsp;&nbsp;<input name="Trial" id="CL_Chk" class="CL_Rdo" type="radio"  value="1" />通过
                                &nbsp;&nbsp;&nbsp;&nbsp;<input name="Trial" class="CL_Rdo" id="CL_UChk"  type="radio" value="0" />不通过
                            </td>
                            <td style="text-align:right;" class="SLBH">受理编号：&nbsp;&nbsp;</td>
                            <td class="formValue SLBH" colspan="2"><input class="form-control" style="border:1px solid #ccc;" id="CityBurceauCode" type="text" /></td>
                            <td colspan="2"></td>

                        </tr>
                        <tr id="Try1" hidden>
                            <td class="formTitle" style="text-align:right;">不通过原因:</td>
                            <td class="formValue" colspan="10">
                                <textarea class="form-control" id="Memo1" style="height:50px;"></textarea>
                            </td>
                        </tr>
                    </table>
                    <table class="form" id="SJSP">
                        <tr>
                            <td class="formTitle"><h4>市局审批</h4></td>
                            <td></td>
                            <td>第<span style="color:red;font-size:24px;">1</span>次提交</td>
                        </tr>
                        <tr style="height:10px;"></tr>
                        <tr>
                            <td></td>
                            <td style="text-align:right;">
                                &nbsp;&nbsp;<input name="Trial2" id="SJ_Chk" class="SJ_Rdo" type="radio"  value="1" />通过
                                &nbsp;&nbsp;&nbsp;&nbsp;<input name="Trial2" class="SJ_Rdo" id="SJ_UChk"  type="radio" value="0" />不通过
                            </td>
                            <td style="text-align:right;">批复日期：&nbsp;&nbsp;</td>
                            <td>@LeSoft.Util.Time.GetToday("yyyy-MM-dd HH:mm:ss")</td>
                            <td style="text-align:right ;">录入人：&nbsp;&nbsp;</td>
                            <td>@ViewBag.Man</td>
                        </tr>
                        <tr style="height:10px;"></tr>
                        <tr id="Try2" hidden>
                            <td colspan="2"></td>
                            <td style="text-align:right;">不通过原因：&nbsp;&nbsp;</td>
                            <td class="formValue" style="border:1px solid #ccc;" colspan="5"><input class="form-control" id="Memo2" type="text" /></td>

                        </tr>
                    </table>
                    <table class="form" id="SLZXSP">
                        <tr>
                            <td class="formTitle"><h4>受理中心复审</h4></td>
                            <td></td>
                            <td>第<span style="color:red;font-size:24px;">1</span>次提交</td>
                        </tr>
                        <tr style="height:10px;"></tr>
                        <tr>
                            <td></td>
                            <td style="text-align:right;">
                                &nbsp;&nbsp;<input name="Trial3" id="SLZX_Chk" class="SHZX_Rdo" type="radio"  value="1" />通过
                                &nbsp;&nbsp;&nbsp;&nbsp;<input name="Trial3" id="SLZX_Uchk" class="SHZX_Rdo"  type="radio" value="0" />不通过
                            </td>
                            <td style="text-align:right;">批复日期：&nbsp;&nbsp; </td>
                            <td>@LeSoft.Util.Time.GetToday("yyyy-MM-dd HH:mm:ss")</td>
                            <td style="text-align:right;">录入人：&nbsp;&nbsp;</td>
                            <td>@ViewBag.Man</td>
                        </tr>
                        <tr style="height:10px;"></tr>
                        <tr id="Try3" hidden>
                            <td colspan="2"></td>
                            <td style="text-align:right;">不通过原因：&nbsp;&nbsp;</td>
                            <td class="formValue" style="border:1px solid #ccc;" colspan="5"><input class="form-control" id="Memo3" type="text" /></td>

                        </tr>
                    </table>
                </div>
                <div id="TrialRecord" style="display: none;">
                    <div class="title">
                        审核记录
                    </div>

                    <div class="gridPanel">
                        <table id="gridTable2"></table>
                        <div id="gridPager2"></div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>